package com.xyzwps.orm.mybatis.mapper;

import com.xyzwps.orm.model.Tag;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface TagMapper {

    @Insert("insert into tag (user_id, tag_name) values (#{userId}, #{tagName})")
    @Options(useGeneratedKeys = true, keyProperty = "tagId", keyColumn = "tag_id")
    void insert(Tag tag);

    @Update("update tag set user_id = #{userId}, tag_name = #{tagName} where tag_id = #{tagId}")
    void update(Tag tag);

    @Select("select tag_id, user_id, tag_name from tag where tag_id = #{tagId}")
    Tag selectByTagId(int tagId);

    @Delete("delete from tag where tag_id = #{tagId}")
    void delete(int tagId);

    @Delete("delete from tag")
    void deleteAll();

    @Select("select tag_id, user_id, tag_name from tag where user_id = #{userId}")
    List<Tag> selectByUserId(int userId);
}
